home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
editors
/
mjovesrc.zoo
/
proc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-04
|
20KB
|
911 lines
/***************************************************************************
* This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
* is provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
***************************************************************************/
#include "jove.h"
#include "ctype.h"
#include "fp.h"
#include "re.h"
#include "termcap.h"
#include "disp.h"
#include "rec.h"
#include <signal.h>
#ifdef STDARGS
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#ifdef MSDOS
# include <io.h>
# include <process.h>
#endif
private void
DoShell proto((char *, char *)),
com_finish proto((int, char *));
long SigMask = 0;
/* This disgusting RE search string parses output from the GREP
family, from the pdp11 compiler, pcc, and lint. Jay (HACK)
Fenlasen changed this to work for the lint errors. */
char ErrFmtStr[256] = "^\\{\",\\}\\([^:\"( \t]*\\)\\{\"\\, line ,:,(\\} *\\([0-9][0-9]*\\)[:)]\
\\|:: *\\([^(]*\\)(\\([0-9]*\\))$\
\\|( \\([^(]*\\)(\\([0-9]*\\)) ),";
struct error {
Buffer *er_buf; /* Buffer error is in */
Line *er_mess, /* Actual error message */
*er_text; /* Actual error */
int er_char; /* char pos of error */
struct error *er_prev, /* List of errors */
*er_next;
};
private struct error *cur_error = NULL,
*errorlist = NULL;
Buffer *perr_buf = NULL; /* Buffer with error messages */
bool WtOnMk = ON; /* Write the modified files when we make */
/* Eliminate any error records that contain dangling references to Lines.
* We only eliminate error structs when either referent is recycled.
* If it deleted, we keep it (dormant) in case it will be pasted back
* into the same buffer.
*/
void
ChkErrorLines()
{
register struct error *e;
struct error *prev = NULL;
for (e = errorlist; e != NULL; ) {
struct error *next = e->er_next;
if (e->er_mess->l_dline == NULL_DADDR
|| e->er_text->l_dline == NULL_DADDR)
{
/* dangling reference: delete */
if (prev == NULL)
errorlist = next;
else
prev->er_next = next;
if (next != NULL)
next->er_prev = prev;
if (cur_error == e)
cur_error = next;
free((UnivPtr)e);
} else {
prev = e;
}
e = next;
}
}
/* Add an error to the end of the list of errors. This is used for
parse-{C,LINT}-errors and for the spell-buffer command */
private struct error *
AddError(laste, errline, buf, line, charpos)
struct error *laste;
Line *errline,
*line;
Buffer *buf;
int charpos;
{
struct error *new = (struct error *) emalloc(sizeof *new);
new->er_prev = laste;
if (laste)
laste->er_next = new;
else {
if (errorlist) /* Free up old errors */
ErrFree();
cur_error = errorlist = new;
}
laste = new;
new->er_next = NULL;
new->er_buf = buf;
new->er_text = line;
new->er_char = charpos;
new->er_mess = errline;
return new;
}
void
get_FL_info(fname, lineno)
char *fname,
*lineno;
{
putmatch(1, fname, (size_t)FILESIZE);
putmatch(2, lineno, (size_t)FILESIZE);
/* error had lineno followed fname, so switch the two */
if (!jisdigit(lineno[0])) {
char tmp[FILESIZE];
strcpy(tmp, lineno);
strcpy(lineno, fname);
strcpy(fname, tmp);
}
}
/* Free up all the errors */
void
ErrFree()
{
register struct error *ep;
for (ep = errorlist; ep != NULL; ep = ep->er_next)
free((UnivPtr) ep);
errorlist = cur_error = NULL;
}
/* Parse errors of the form specified in ErrFmtStr in the current
buffer. Do a show error of the first error. This is neat because this
will work for any kind of output that prints a file name and a line
number on the same line. */
void
ErrParse()
{
struct RE_block re_blk;
Bufpos *bp;
char fname[FILESIZE],
lineno[FILESIZE];
int lnum,
last_lnum = -1;
struct error *ep = NULL;
Buffer *buf,
*lastb = NULL;
Line *err_line;
ErrFree(); /* This is important! */
ToFirst();
perr_buf = curbuf;
REcompile(ErrFmtStr, YES, &re_blk);
/* Find a line with a number on it. */
while ((bp = docompiled(FORWARD, &re_blk)) != NULL) {
SetDot(bp);
get_FL_info(fname, lineno);
buf = do_find((Window *)NULL, fname, YES);
if (buf != lastb) {
lastb = buf;
last_lnum = -1; /* signals new file */
err_line = buf->b_first;
}
(void) chr_to_int(lineno, 10, NO, &lnum);
if (lnum == last_lnum) /* one error per line is nicer */
continue;
if (last_lnum == -1)
last_lnum = 1; /* that's where we really are */
err_line = next_line(err_line, lnum - last_lnum);
ep = AddError(ep, curline, buf, err_line, 0);
last_lnum = lnum;
}
if (cur_error != NULL)
ShowErr();
}
private void
NeedErrors()
{
if (cur_error == NULL)
complain("No errors!");
}
private bool
ErrorHasReferents()
{
return inlist(cur_error->er_buf->b_first, cur_error->er_text)
&& inlist(perr_buf->b_first, cur_error->er_mess);
}
/* Go the the next error, if there is one. Put the error buffer in
one window and the buffer with the error in another window.
It checks to make sure that the error actually exists. */
private void
ToError(forward)
bool forward;
{
register struct error *e = cur_error;
int num = arg_value();
NeedErrors();
if ((forward? e->er_next : e->er_prev) == NULL)
complain("You're at the %s error.", forward ? "last" : "first");
while (--num >= 0 || !ErrorHasReferents()) {
e = forward ? e->er_next : e->er_prev;
if (e == NULL)
break;
cur_error = e;
}
ShowErr();
}
void
NextError()
{
ToError(TRUE);
}
void
PrevError()
{
ToError(FALSE);
}
int EWSize = 20; /* percentage of screen the error window
should be */
private void
set_wsize(wsize)
int wsize;
{
wsize = (LI * wsize) / 100;
if (wsize >= 1 && !one_windp())
WindSize(curwind, wsize - (curwind->w_height - 1));
}
/* Show the current error, i.e. put the line containing the error message
in one window, and the buffer containing the actual error in another
window. */
void
ShowErr()
{
Window *err_wind,
*buf_wind;
NeedErrors();
if (!ErrorHasReferents()) {
rbell();
return;
}
err_wind = windbp(perr_buf);
buf_wind = windbp(cur_error->er_buf);
if (err_wind && !buf_wind) {
SetWind(err_wind);
pop_wind(cur_error->er_buf->b_name, NO, -1);
buf_wind = curwind;
} else if (!err_wind && buf_wind) {
SetWind(buf_wind);
pop_wind(perr_buf->b_name, NO, -1);
err_wind = curwind;
} else if (!err_wind && !buf_wind) {
pop_wind(perr_buf->b_name, NO, -1);
err_wind = curwind;
pop_wind(cur_error->er_buf->b_name, NO, -1);
buf_wind = curwind;
}
/* Put the current error message at the top of its Window */
SetWind(err_wind);
SetLine(cur_error->er_mess);
SetTop(curwind, (curwind->w_line = cur_error->er_mess));
set_wsize(EWSize);
/* now go to the the line with the error in the other window */
SetWind(buf_wind);
DotTo(cur_error->er_text, cur_error->er_char);
}
char ShcomBuf[LBSIZE];
/* Make a buffer name given the command `command', i.e. "fgrep -n foo *.c"
will return the buffer name "fgrep". */
char *
MakeName(command)
char *command;
{
static char bnm[50];
register char *cp = bnm,
c;
do ; while ((c = *command++) != '\0' && (c == ' ' || c == '\t'));
do {
*cp++ = c;
} while ((c = *command++) != '\0' && (c != ' ' && c != '\t'));
*cp = '\0';
strcpy(bnm, basename(bnm));
return bnm;
}
/* Run make, first writing all the modified buffers (if the WtOnMk flag is
on), parse the errors, and go the first error. */
private char make_cmd[LBSIZE] = "make";
void
MakeErrors()
{
Window *old = curwind;
int status;
bool compilation;
#ifdef MiNT
#include <ioctl.h>
struct sgttyb sg;
int tfd, set;
#endif /* MiNT */
if (WtOnMk)
put_bufs(FALSE);
/* When we're not doing make or cc (i.e., the last command
was probably a grep or something) and the user just types
C-X C-E, he probably (possibly, hopefully, usually (in my
case)) doesn't want to do the grep again but rather wants
to do a make again; so we ring the bell and insert the
default command and let the person decide. */
compilation = (sindex("make", make_cmd) || sindex("cc", make_cmd));
if (is_an_arg() || !comp